<?php if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class faqs extends CI_Controller {
	
	function __construct() {
			parent::__construct();
			
			$this->load->library('ion_auth');
			$this->load->library('form_validation');
			$this->load->library('session');
			$this->load->library('pagination');
			$this->load->database();
			$this->lang->load('auth');
                        $this->lang->load('admin_estate');
			$this->load->helper('language');
			$this->load->model('faqs_model');
			if (!$this->ion_auth->logged_in()) {
				redirect('login');
			}
			$this->data['ptitle'] = 'Faq';
		}

	public function index(){
		$this->session->set_userdata('page', 0);
		$this->data['questions'] = $this->faqs_model->get_faqs();
		
        $this->tmadmin->tmView('faqs/faqs', $this->data);
	}
	
	public function view(){
	$loaded='';
	$this->session->set_userdata('page', 0);
	$this->data['question_details'] = $this->_get_page($this->uri->segment(3));
	if ($this->uri->segment(3) == 'edit_question') {
		$loaded = 'edit_question';
	}else{
		$loaded = 'add_question';
	}
	$this->tmadmin->tmView('faqs/'.$loaded, $this->data);
	
	}
	
	
	function _get_page($status){
		switch ($status) {
			case 'edit_question':
				return $this->faqs_model->question_details($this->uri->segment(4));
				break;
			default:
				
			  break;
		}
		
	}
	
	public function insert_question()
	{
		$data = array(
		'question' => $this->input->post('question'),
		'author' => $this->ion_auth->get_user_id(),
		'answer' => $this->input->post('answer')
		);
		$this->db->insert('faqs',$data);
		
		$this->session->set_flashdata('message','<div class="alert alert-success"> <p>Record Successfully Created</p> </div>');

		redirect('faqs/view/add_question');
	}
	
	
	
	public function update_question()
	{
	    $id = $this->input->post('q_id');
		$data = array(
		'question' => $this->input->post('question'),
		'author' => $this->ion_auth->get_user_id(),
		'answer' => $this->input->post('answer')
		);
		$this->db->where('q_id',$id);
		$this->db->update('faqs',$data);
		
		$this->session->set_flashdata('message','<div class="alert alert-success"> <p>Record Successfully Updated</p> </div>');
		
		
		redirect('faqs/view/edit_question/'.$id);
	}
	
	
	
	
	
	public function delete_question($question){
		
		$this->db->where('q_id',$question);
		$this->db->delete('faqs',$data);
		$this->session->set_flashdata('message','<div class="alert alert-success"> <p>Record Successfully Deleted</p> </div>');
		
		redirect('faqs');
	}
	
}

/* End of file Faqs.php */